package cn.yiyuan.service.impl;

import cn.yiyuan.base.untli.PageInfo;
import cn.yiyuan.domain.Emp;
import cn.yiyuan.mapper.EmpMapper;
import cn.yiyuan.query.EmpQuery;
import cn.yiyuan.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project system_boog
 * @date 2023-10-09
 * @package cn.yiyuan.service.impl
 */
//事务
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
@Service
//引入mapper
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;



    @Transactional
    @Override
    public void insert(Emp emp) {
        empMapper.insert(emp);
    }

    @Transactional
    @Override
    public void delete(Serializable id) {
        empMapper.delete(id);
//        System.out.println(1/0);
    }

    @Transactional
    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }

    @Override
    public List<Emp> getAllEmp() {
        return empMapper.getAllEmp();
    }

    @Override
    public Emp getByIdEmp(Serializable id) {
        return empMapper.getByIdEmp(id);
    }




    @Override
    public PageInfo<Emp> queryList(EmpQuery empQuery) {
        //查询总条数
        Long total =  empMapper.queryTotal(empQuery);
        //查询分页数据
        if (total != 0){
            List<Emp>list = empMapper.queryList(empQuery);
        return new PageInfo<Emp> (total,list);
        }
        return new PageInfo<Emp>();
    }
}
